/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mudalov.rec.util.webui;

import com.sun.webui.jsf.component.PageAlert;
import com.sun.webui.jsf.util.MessageUtil;
import javax.faces.context.FacesContext;

/**
 *
 * @author Mikhail_Udalov
 */
public class MessagesHelper {

    public static void processErrorAlert(PageAlert alert, String message) {
        processAlert(alert, MessagesHelper.getMessage("error"), message, "error");
    }
    
    public static void processInformAlert(PageAlert alert, String message) {
        processAlert(alert, MessagesHelper.getMessage("information"), message, "information");
    }

    public static void processWarnAlert(PageAlert alert, String message) {
        processAlert(alert, MessagesHelper.getMessage("warning"), message, "warning");
    }

    private static void processAlert(PageAlert alert, String title, String message, String type) {
        if (alert == null) {
            alert = new PageAlert();
        }
        alert.setVisible(true);
        alert.setTitle(title);
        alert.setSummary(message);
        alert.setType(type);
    }

    public static String getMessage(String key) {
        FacesContext context = FacesContext.getCurrentInstance();
		return MessageUtil.getMessage(context, "com.mudalov.rec.web.Messages", key);
    }
}
